package com.fenghuajueli.libbasecoreui.adapter;

import android.annotation.SuppressLint;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.bumptech.glide.Glide;
import com.fenghuajueli.libbasecoreui.R;
import com.fenghuajueli.libbasecoreui.feedback.XuqiuBean;

import java.util.ArrayList;

/**
 * vip描述功能适配器
 */
public class XuqiuAdapter extends RecyclerView.Adapter<XuqiuAdapter.ViewHolder> {

    private final ArrayList<XuqiuBean> data;
    private Context context;
    private OnItemClickLitener mOnItemClickLitener;

    public XuqiuAdapter(Context context, ArrayList<XuqiuBean> data) {
        this.context = context;
        this.data = data;
    }

    //定义点击接口
    public interface OnItemClickLitener {
        void onItemClick(int position);
    }

    public void setOnItemClickLitener(OnItemClickLitener mOnItemClickLitener) {
        this.mOnItemClickLitener = mOnItemClickLitener;
    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        return new ViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_xq, parent, false));
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, @SuppressLint("RecyclerView") int position) {
        int status = data.get(position).getStatus();
        if (status == 0){
           holder.img_dz.setImageResource(R.mipmap.icon_choice_nor);
        }else {
            holder.img_dz.setImageResource(R.mipmap.icon_choice_sel);
        }
        holder.tv_xq.setText(data.get(position).getContent());
        holder.tv_dz.setText(""+data.get(position).getLikes());
        holder.img_dz.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mOnItemClickLitener.onItemClick(position);
            }
        });
    }

    @Override
    public int getItemCount() {
        return data.size();
    }

    public static class ViewHolder extends RecyclerView.ViewHolder {

        private  ImageView img_dz;
        private TextView tv_xq,tv_dz;

        public ViewHolder(@NonNull View itemView) {
            super(itemView);
            tv_dz = itemView.findViewById(R.id.tv_dz);
            img_dz = itemView.findViewById(R.id.img_dz);
            tv_xq = itemView.findViewById(R.id.tv_xq);
        }
    }
}